var opinionPrice;

/**
 * 设置结果接收对象
 * @param _opinionPrice
 */
function setModel(_opinionPrice) {
    if (_opinionPrice == undefined || !(_opinionPrice instanceof com.jf.crawl.model.OpinionPrice)) {
        throw new java.lang.Exception("opinionPrice 对象为空");
    }
    log.info("opinionPrice {}", _opinionPrice)
    opinionPrice = _opinionPrice;
}

function crawler() {
    //搜易贷
    //    30--988
    //    36--900
    //    12--850
    //    12--850
    //    10--850
    var result = httpClient.Get("https://www.souyidai.com/soeasy/invest/onlinelist?productType=1&pageNo=0&repayMode=-1&orderBy=DEFAULT");
    var jsonObject = JSON.parseObject(result);
    if (jsonObject.containsKey("data")) {
        var jsonArray = jsonObject.getJSONObject("data").getJSONObject("page").getJSONArray("data");
        //第一个新手专享不需要
        for (var i = 1; i < jsonArray.size(); i++) {
            var jsonObject = jsonArray.getJSONObject(i);
            var month = jsonObject.getString("periods");
            var price = jsonObject.getString("investAnnualRate");
            if ("1".equals(month)) {
                opinionPrice.setOneMonth(commonUtil.string2Decimal(calcPrice(price)));
            } else if ("3".equals(month)) {
                opinionPrice.setThreeMonth(commonUtil.string2Decimal(calcPrice(price)));
            } else if ("6".equals(month)) {
                opinionPrice.setSixMonth(commonUtil.string2Decimal(calcPrice(price)));
            } else if ("12".equals(month)) {
                opinionPrice.setOneYear(commonUtil.string2Decimal(calcPrice(price)));
            } else if ("24".equals(month)) {
                opinionPrice.setTwoYear(commonUtil.string2Decimal(calcPrice(price)));
            } else if ("36".equals(month)) {
                opinionPrice.setThreeYear(commonUtil.string2Decimal(calcPrice(price)));
            }
        }
    }
    return true;
}

//处理价格利率988-->9.88
function calcPrice(price) {
    return Number(price) / 100.0;
}